<template>
    <div>
        <hd-tab :tabs="tabs"/>
        <el-form
                :model="form"
                ref="form"
                label-width="120px"
                :inline="false"
                size="normal"
        >
            <el-form-item label="公众号标题">
                <el-input v-model="form.title"></el-input>
                <hd-error name="title"/>
            </el-form-item>
            <el-form-item label="公众号名称">
                <el-input v-model="form.name"></el-input>
                <hd-error name="name"/>
            </el-form-item>
            <el-form-item label="公众号介绍">
                <el-input v-model="form.introduce"></el-input>
                <hd-error name="introduce"/>
            </el-form-item>
            <el-form-item label="二维码">
                <hd-image v-model="form.qr"></hd-image>
                <hd-error name="qr"/>
            </el-form-item>

            <el-form-item label="类型">
                <el-input v-model="form.type"></el-input>
                <hd-error name="type"/>
            </el-form-item>
            <el-form-item label="TOKEN">
                <el-input v-model="form.token"></el-input>
                <hd-error name="token"/>
            </el-form-item>
            <el-form-item label="原始ID">
                <el-input v-model="form.wechat_id"></el-input>
                <hd-error name="wechat_id"/>
            </el-form-item>
            <el-form-item label="APPID">
                <el-input v-model="form.appid"></el-input>
                <hd-error name="appid"/>
            </el-form-item>
            <el-form-item label="appsecret">
                <el-input v-model="form.appsecret"></el-input>
                <hd-error name="appsecret"/>
            </el-form-item>
            <el-form-item>
                <el-button type="primary" @click="onSubmit" class="mt-3">
                    保存资料
                </el-button>
            </el-form-item>
        </el-form>
    </div>
</template>

<script>
    import tabs from "./tabs";

    const form = {};
    export default {
        route: false,
        props: ["id"],
        data() {
            return {
                tabs: tabs(this.$route.params.sid),
                form,
                sid: this.$route.params.sid
            }
        },
        async created() {
            if (this.id) this.form = await this.axios.get(`site/${this.sid}/wechat/${this.id}`);
        },
        methods: {
            async onSubmit() {
                const url = this.id ? `site/${this.sid}/wechat/${this.id}` : `site/${this.sid}/wechat`;
                await this.axios[this.id ? "put" : "post"](url, this.form);
                this.router("wechat.wechat.index");
            },
        }
    };
</script>

<style></style>
